﻿using System;
using System.Linq;

namespace CalcIntegerSquareRoot
{
    class CalcIntegerSquareRoot
    {
        static void Main(string[] args)
        {
            /* 1. Write a program that reads an integer number and calculates and prints its square root. 
             * If the number is invalid or negative, print "Invalid number". In all cases finally print "Good bye". 
             * Use try-catch-finally.
             */
            
            try
            {
                Console.Write("Enter a integer number: ");
                string number = Console.ReadLine();
                
                if (Int32.Parse(number) < 0)
                {
                    throw new InvalidOperationException();
                }

                double root = Math.Sqrt(double.Parse(number));
                Console.WriteLine("Square root of {0} is {1}", number, root);
            }
            catch (FormatException)
            {
                Console.WriteLine("Invalid number");
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("Invalid number");
            }
            finally
            {
                Console.WriteLine("Good bye");
            }

        }
    }
}
